package com.minshenglife.zanzan.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.minshenglife.commons.dal.Page;
import com.minshenglife.zanzan.dao.EndPlateReviewDao;
import com.minshenglife.zanzan.entity.EndPlateReview;
import com.minshenglife.zanzan.pub.CalcUtils;
import com.minshenglife.zanzan.result.EndPlateReviewResult;
import com.minshenglife.zanzan.service.EndPlateReviewService;


/**
 * 吐槽service
 * @author huodd
 *
 */
@Component
@Transactional
public class EndPlateReviewServiceImpl  implements EndPlateReviewService {
	Logger log = LoggerFactory.getLogger(EndPlateReviewServiceImpl.class);
	@Resource
	private EndPlateReviewDao endPlateReviewDao;
	/**
	 * 吐槽列表
	 */
	@Override
	public Page<EndPlateReviewResult> findEndPlateInfo(String endPlateId,int pageNo,int pageSize){
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("endPlateId", endPlateId);
		int offset = (pageNo-1) * pageSize;
        Long count =endPlateReviewDao.countByParams(map);
        map.put("from", offset);
        map.put("to", offset+pageSize);
        List<EndPlateReviewResult> rows =endPlateReviewDao.findEndPlateReviewInfo(map);
        Page<EndPlateReviewResult> epr = new Page<EndPlateReviewResult>();
        epr.setRows(rows);
        epr.setTotalRow(count);
        epr.setTotalPage(CalcUtils.calcTotalPage(pageSize, count));
        epr.setPageSize(pageSize);
        epr.setPageNo(pageNo);
        return epr;
	}
	
	/**
	 * 吐槽评论
	 */
	@Override
	public void add(EndPlateReview endPlate) {
		log.debug("start insert EndPlateReview info");
		endPlateReviewDao.add(endPlate);
		log.debug("end insert EndPlateReview info");
	}

}
